﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using timetableasy.Models;

namespace timetableasy.Controllers
{
    public class ProfilesController : Controller
    {
        [Authorize]
        public ViewResult Profile()
        {
            ProfileCommon profile = ProfileCommon.GetUserProfileByLogin(User.Identity.Name);
            var model = new UserProfileViewModel
            {
                FirstName = profile.FirstName,
                LastName = profile.LastName
            };
            return View(model);
        }

        [HttpPost]
        [Authorize]
        public ActionResult Profile(UserProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                ProfileCommon profile = ProfileCommon.GetUserProfileByLogin(User.Identity.Name);
                profile.FirstName = model.FirstName;
                profile.LastName = model.LastName;
                profile.Save();
                return RedirectToRoute("Account.Profile");
            }
            return View(model);
        }

    }
}
